﻿using ReflectionStudio.Components.UserControls;
using ReflectionStudio.Core.Events;
using System;
using System.ComponentModel;
using System.Data;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace WPFExcelReport
{
    /// <summary>
    /// 列举出现有的相关的发货单
    /// 新建发货单
    /// 将销售单行加入现在的发货单
    /// 新建发货单必须选择其中一行，建立VVT和VV
    /// </summary>
    public partial class SXNWB06
    {
        #region ==IsWBFull===========
        public static readonly DependencyProperty IsWBFullProperty = DependencyProperty.Register("IsWBFull",
            typeof(bool), typeof(SXNWB06),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsWBFullChanged));
        public bool IsWBFull
        {
            get
            {
                return (bool)GetValue(IsWBFullProperty);
            }
            set
            {
                SetValue(IsWBFullProperty, value);
                OnIsWBFullChg(value);
            }
        }
        private static void OnIsWBFullChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as SXNWB06;
            if (src != null)
            {
                src.IsWBFull = (bool)e.NewValue;
            }
        }
        #endregion
        public void OnIsWBFullChg(bool value)
        {
            if (value)
            {

                ZoneVK.Visibility = Visibility.Collapsed;
                ZoneWB.SetValue(Grid.RowProperty, 1);
                ZoneWB.SetValue(Grid.RowSpanProperty, 2);
            }
            else
            {
                ZoneVK.Visibility = Visibility.Visible;
                ZoneWB.SetValue(Grid.RowProperty, 2);
                ZoneWB.SetValue(Grid.RowSpanProperty, 1);
            }
        }
        #region ==VKAUF===========
        public static readonly DependencyProperty VKAUFProperty = DependencyProperty.Register("VKAUF",
            typeof(string), typeof(SXNWB06),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnVKAUFChanged));
        public string VKAUF
        {
            get
            {
                return (string)GetValue(VKAUFProperty);
            }
            set
            {
                SetValue(VKAUFProperty, value);
            }
        }
        private static void OnVKAUFChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as SXNWB06;
            if (src != null)
            {
                src.VKAUF = (string)e.NewValue;
            }
        }
        #endregion
       
        ITXEXRPT ITXEXRPT;
        private ApplicationBase app
        {
            get
            {
                return ApplicationBase.Instance;
            }
        }
        VSXNWB06 vm;
      
        public SXNWB06()
        { 
            vm = new VSXNWB06();
            DataContext = vm;
            InitializeComponent();
            this.Name = "出货确认";
            if (ITXEXRPT == null)
            {
                ITXEXRPT = new ITXEXRPT();
                ITXEXRPT.Root = "C:\\IntexReport";
                ITXEXRPT.strCompany = app.company;
                ITXEXRPT.PrintType = "OpenExcel";
            }
            cVK04.LFD = "000011";
            cVK05.ARTST = "F";
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            
        } 
        private void btnPrintPK_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                ITXEXRPT.dsSource = new DataSet();
                ITXEXRPT.DocType = "JLTVV03PKCN";
                if (txtLang.Text == "EN")
                {
                    ITXEXRPT.DocType = "JLTVV03PKEN";
                }
                ITXEXRPT.dsSource.Merge(cVVT.MV.SetProd);
                ITXEXRPT.dsSource.Merge(this.cVK05.MV.SetProd);
                ITXEXRPT.dsSource.Merge(this.cWZ04.MV.SetProd);
                DataSet SResult = ((VVKPOS)cVK05.MV).QueryVKP(cVK05.dwVKP);
                ITXEXRPT.dsSource.Merge(SResult);
                ITXEXRPT.strExcelFile = @"\JLT\JLTVVDOC.xls";
                string filename = ITXEXRPT.WriteExcelReport();

            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        } 

        private void VR02Command(object sender, RoutedEventArgs e)
        {
            VICC_WFEVENTS.SVWF.VR02(RUNID, VKAUF);
        }
   
    }
}
